package com.youaishujuhui.devops.web.service.game;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.service.IdEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youaishujuhui.devops.web.dao.game.GameDao;
import com.youaishujuhui.devops.web.domain.game.Game;
import com.youaishujuhui.devops.web.po.GamePO;


@Service
public class GameService extends IdEntityService<Game> {

	@Autowired
	private GameDao gameDao;

	public List<Game> query(Map<String, Object> param) {
		return gameDao.query(param);
	}

	public List<GamePO> queryAllGamePO() {
		List<Game> games = query(Cnd.where("state", "=", 1));
		List<GamePO> list = new ArrayList<GamePO>();
		
		if (games != null) {
			for (Game game : games) {
				GamePO po = new GamePO();
				po.setId(game.getGameId());
				po.setText(game.getNameCn());
				list.add(po);
			}
		}
		
		return list;
	}
	
	public Game fetchExistGame(int gameId) {
		return fetch(Cnd.where("gameId", "=", gameId).and("state", "=", 1));
	}
	
	@Resource(name = "nutDao")
	@Override
	public void setDao(Dao dao) {
		super.setDao(dao);
	}
}
